package client;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Client extends JFrame implements ActionListener{

	private int xSize = 800;
	private int ySize = 800;
	
	public static User user;
	
	private LoginPanel loginPanel;
	private LogoutPanel logoutPanel;
	private NavigationPanel navigation;
	private HomePanel homePanel;
	private JPanel main;
	private JPanel container;
	private JPanel view;
	
	public static Client c;
	
	public Client(){
		c = this;
		Dimension d  = new Dimension(xSize, ySize);
		setSize(d);
		setPreferredSize(d);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		loginPanel = new LoginPanel(this);
		logoutPanel = new LogoutPanel(this);
		homePanel = new HomePanel();
		main = new JPanel(new BorderLayout());
		main.add(navigation = new NavigationPanel(), BorderLayout.NORTH);
		container = new JPanel(new BorderLayout());
		view = homePanel;
		container.add(view);
		main.add(container, BorderLayout.CENTER);
		add(main);
		setVisible(true);
	}
	
	public void setCenter(JPanel center, LayoutManager lm){
		container.setLayout(lm);
		if(view!=null){
			container.remove(view);
		}
		view = center;
		container.add(view);
		container.updateUI();
	}
	public void setCenter(JPanel center){
		setCenter(center, new BorderLayout());
	}
	public void actionPerformed(ActionEvent e) {
		user = loginPanel.getUser();
		navigation.login(user);
		setCenter(homePanel);
	}
	
	public static void main(String[] e){
		new Client();
	}

	public void setHome() {
		setCenter(homePanel);
	}

	public void logout() {
		setCenter(logoutPanel, null);
	}

	public void login() {
		setCenter(loginPanel, null);
	}
	public void register(){
		setCenter(new RegisterPanel(this), null);
	}
	
}
